<?php
namespace app\admin\controller;
use think\facade\App;
use think\facade\Db;
use think\facade\Session;
use think\facade\View;
use app\common\model\Article as A;
use app\common\model\Page as P;
use app\common\model\Goods as G;
class Index extends Base
{
    public function index()
    {
        return View::fetch();
    }
    public function home(){
        $mysqlVersion = Db::query('SELECT VERSION() AS ver');
        $view = [
            'artdata' => A::where('status',1)->count(),
            'pagedata' => P::where('status',1)->count(),
            'goodsdata' => G::where('goods_status',1)->count(),
            'url'             => $_SERVER['HTTP_HOST'],
            'document_root'   => $_SERVER['DOCUMENT_ROOT'],
            'server_os'       => PHP_OS,
            'server_port'     => $_SERVER['SERVER_PORT'],
            'server_ip'       => isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '',
            'server_soft'     => $_SERVER['SERVER_SOFTWARE'],
            'mysql_version'   => $mysqlVersion[0]['ver'],
            'php_version'     => PHP_VERSION,
            'max_upload_size' => ini_get('upload_max_filesize'),
            'version'         => App::version(),
        ];
        View::assign($view);
        return View::fetch();
    }
    public function logout(){
        Session::delete('admin');
        return redirect('login/index');
    }

    /**
     * 清除缓存
     */
    // 清除缓存
    public function clear()
    {
        $path = App::getRootPath() . 'runtime' . DIRECTORY_SEPARATOR;
        if (delete_dir_file($path)) {
            $result['msg'] = '清除缓存成功!';
            $result['code'] = 1;
        } else {
            $result['msg'] = '清除缓存失败!';
            $result['error'] = 1;
        }
        $result['url'] = url();
        return json($result);
    }

}
